package adapter;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.remotecontrol.R;

import data.SMSLog;

public class SMSLogAdapter extends ArrayAdapter<SMSLog> {
	private Context context = null;
	private List<SMSLog> mListItem = null;
	private int mResourceID = 0;

	public SMSLogAdapter(Context context, List<SMSLog> objects) {
		super(context, R.layout.item_sms_log, objects);

		this.context = context;
		mListItem = objects;
		mResourceID = R.layout.item_sms_log;
		// TODO Auto-generated constructor stub
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View row;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context
					.getApplicationContext().getSystemService(
							Context.LAYOUT_INFLATER_SERVICE);
			row = inflater.inflate(this.mResourceID, null);
		} else {
			row = convertView;
		}

		TextView content = (TextView) row.findViewById(R.id.item_option_name);
		TextView date = (TextView) row
				.findViewById(R.id.item_options_img_btn_alarm);
		TextView sender = (TextView) row.findViewById(R.id.txt_sender);

		SMSLog item = mListItem.get(position);

		if (item != null) {
			if (item.getContent() != null) {
				content.setText(item.getContent());
			}

			if (item.getDate() != null) {
				if (item.getDate() != null) {
					SimpleDateFormat df = new SimpleDateFormat(
							"dd-MM-yyyy HH:mm", new Locale("vi"));
					date.setText(df.format(item.getDate()));
				}
			}

			if (item.getSender() != null) {
				sender.setText(item.getSender());
			}
		}

		return row;
	}

}
